package com.cly.controller;

import com.cly.base.controller.BaseController;
import com.cly.dto.MessageListDto;
import com.cly.entity.Message;
import com.cly.result.JsonRequest;
import com.cly.service.IMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 消息记录业务层实现
 *
 * @author 春风能解释
 * <p>
 * 2024-06-05
 */
@RestController
@RequestMapping("/message")
@Tag(name = "消息记录控制类", description = "消息记录操作访问接口")
public class MessageController extends BaseController<IMessageService, Message> {


    /**
     * 查询消息记录
     *
     * @param messageListDto 消息记录查询条件
     * @return JSON
     */
    @PostMapping("/list")
    @Operation(summary = "查询消息记录")
    public JsonRequest<List<Message>> lookMessage(
            @Parameter(description = "消息记录查询条件", required = true)
            @RequestBody MessageListDto messageListDto) {
        return baseService.lookMessage(messageListDto);
    }

    /**
     * 查看当前用户的最后一条消息记录
     *
     * @param userId 用户id
     * @return JSON
     */
    @PostMapping("/last")
    @Operation(summary = "查看当前用户的最后一条消息记录")
    public JsonRequest<List<Message>> lookMessageLast(
            @Parameter(description = "用户id", required = true)
            @RequestParam Long userId) {
        return baseService.lookMessageLast(userId);
    }

    /**
     * 批量删除消息记录信息
     *
     * @param ids 消息记录id列表
     * @return JSON
     */
    @DeleteMapping
    @Operation(summary = "批量删除消息记录信息")
    public JsonRequest<Integer> deleteMessages(
            @Parameter(description = "消息记录id列表", required = true)
            @RequestBody List<Long> ids) {
        return baseService.deleteMessages(ids);
    }

    /**
     * 发送消息
     *
     * @param message 消息体
     * @return JSON
     */
    @PostMapping("/send")
    @Operation(summary = "发送消息")
    public JsonRequest<Integer> sendMessage(
            @Parameter(description = "消息体", required = true)
            @RequestBody Message message) {
        return baseService.sendMessage(message);
    }

}